<?php

/**
 * CompetitiveSummaryRequest.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Selling Partner API for Pricing.
 *
 * The Selling Partner API for Pricing helps you programmatically retrieve product pricing and offer pricing information for Amazon Marketplace products.  For more information, refer to the [Product Pricing v2022-05-01 Use Case Guide](https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-use-case-guide).
 *
 * The version of the OpenAPI document: 2022-05-01
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\pricing\v2022_05_01;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * CompetitiveSummaryRequest Class Doc Comment.
 *
 * @category Class
 *
 * @description An individual &#x60;competitiveSummary&#x60; request for an ASIN and &#x60;marketplaceId&#x60;.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class CompetitiveSummaryRequest implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'CompetitiveSummaryRequest';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'asin' => 'string',
        'marketplace_id' => 'string',
        'included_data' => '\SpApi\Model\pricing\v2022_05_01\CompetitiveSummaryIncludedData[]',
        'lowest_priced_offers_inputs' => '\SpApi\Model\pricing\v2022_05_01\LowestPricedOffersInput[]',
        'method' => '\SpApi\Model\pricing\v2022_05_01\HttpMethod',
        'uri' => 'string'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'asin' => null,
        'marketplace_id' => null,
        'included_data' => null,
        'lowest_priced_offers_inputs' => null,
        'method' => null,
        'uri' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'asin' => false,
        'marketplace_id' => false,
        'included_data' => false,
        'lowest_priced_offers_inputs' => true,
        'method' => false,
        'uri' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'asin' => 'asin',
        'marketplace_id' => 'marketplaceId',
        'included_data' => 'includedData',
        'lowest_priced_offers_inputs' => 'lowestPricedOffersInputs',
        'method' => 'method',
        'uri' => 'uri',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'asin' => 'setAsin',
        'marketplace_id' => 'setMarketplaceId',
        'included_data' => 'setIncludedData',
        'lowest_priced_offers_inputs' => 'setLowestPricedOffersInputs',
        'method' => 'setMethod',
        'uri' => 'setUri',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'asin' => 'getAsin',
        'marketplace_id' => 'getMarketplaceId',
        'included_data' => 'getIncludedData',
        'lowest_priced_offers_inputs' => 'getLowestPricedOffersInputs',
        'method' => 'getMethod',
        'uri' => 'getUri',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('asin', $data ?? [], null);
        $this->setIfExists('marketplace_id', $data ?? [], null);
        $this->setIfExists('included_data', $data ?? [], null);
        $this->setIfExists('lowest_priced_offers_inputs', $data ?? [], null);
        $this->setIfExists('method', $data ?? [], null);
        $this->setIfExists('uri', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['asin']) {
            $invalidProperties[] = "'asin' can't be null";
        }
        if (null === $this->container['marketplace_id']) {
            $invalidProperties[] = "'marketplace_id' can't be null";
        }
        if (null === $this->container['included_data']) {
            $invalidProperties[] = "'included_data' can't be null";
        }
        if (count($this->container['included_data']) < 1) {
            $invalidProperties[] = "invalid value for 'included_data', number of items must be greater than or equal to 1.";
        }

        if (!is_null($this->container['lowest_priced_offers_inputs']) && (count($this->container['lowest_priced_offers_inputs']) > 5)) {
            $invalidProperties[] = "invalid value for 'lowest_priced_offers_inputs', number of items must be less than or equal to 5.";
        }

        if (!is_null($this->container['lowest_priced_offers_inputs']) && (count($this->container['lowest_priced_offers_inputs']) < 0)) {
            $invalidProperties[] = "invalid value for 'lowest_priced_offers_inputs', number of items must be greater than or equal to 0.";
        }

        if (null === $this->container['method']) {
            $invalidProperties[] = "'method' can't be null";
        }
        if (null === $this->container['uri']) {
            $invalidProperties[] = "'uri' can't be null";
        }
        if (mb_strlen($this->container['uri']) > 512) {
            $invalidProperties[] = "invalid value for 'uri', the character length must be smaller than or equal to 512.";
        }

        if (mb_strlen($this->container['uri']) < 6) {
            $invalidProperties[] = "invalid value for 'uri', the character length must be bigger than or equal to 6.";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets asin.
     */
    public function getAsin(): string
    {
        return $this->container['asin'];
    }

    /**
     * Sets asin.
     *
     * @param string $asin the ASIN of the item
     */
    public function setAsin(string $asin): self
    {
        if (is_null($asin)) {
            throw new \InvalidArgumentException('non-nullable asin cannot be null');
        }
        $this->container['asin'] = $asin;

        return $this;
    }

    /**
     * Gets marketplace_id.
     */
    public function getMarketplaceId(): string
    {
        return $this->container['marketplace_id'];
    }

    /**
     * Sets marketplace_id.
     *
     * @param string $marketplace_id The marketplace ID is the globally unique identifier of a marketplace. To find the ID for your marketplace, refer to [Marketplace IDs](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids).
     */
    public function setMarketplaceId(string $marketplace_id): self
    {
        if (is_null($marketplace_id)) {
            throw new \InvalidArgumentException('non-nullable marketplace_id cannot be null');
        }
        $this->container['marketplace_id'] = $marketplace_id;

        return $this;
    }

    /**
     * Gets included_data.
     */
    public function getIncludedData(): array
    {
        return $this->container['included_data'];
    }

    /**
     * Sets included_data.
     *
     * @param array $included_data the list of requested competitive pricing data for the product
     */
    public function setIncludedData(array $included_data): self
    {
        if (is_null($included_data)) {
            throw new \InvalidArgumentException('non-nullable included_data cannot be null');
        }

        if (count($included_data) < 1) {
            throw new \InvalidArgumentException('invalid length for $included_data when calling CompetitiveSummaryRequest., number of items must be greater than or equal to 1.');
        }
        $this->container['included_data'] = $included_data;

        return $this;
    }

    /**
     * Gets lowest_priced_offers_inputs.
     */
    public function getLowestPricedOffersInputs(): ?array
    {
        return $this->container['lowest_priced_offers_inputs'];
    }

    /**
     * Sets lowest_priced_offers_inputs.
     *
     * @param null|array $lowest_priced_offers_inputs The list of `lowestPricedOffersInput` parameters that are used to build `lowestPricedOffers` in the response. This attribute is only valid if `lowestPricedOffers` is requested in `includedData`
     */
    public function setLowestPricedOffersInputs(?array $lowest_priced_offers_inputs): self
    {
        if (is_null($lowest_priced_offers_inputs)) {
            array_push($this->openAPINullablesSetToNull, 'lowest_priced_offers_inputs');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('lowest_priced_offers_inputs', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        if (!is_null($lowest_priced_offers_inputs) && (count($lowest_priced_offers_inputs) > 5)) {
            throw new \InvalidArgumentException('invalid value for $lowest_priced_offers_inputs when calling CompetitiveSummaryRequest., number of items must be less than or equal to 5.');
        }
        if (!is_null($lowest_priced_offers_inputs) && (count($lowest_priced_offers_inputs) < 0)) {
            throw new \InvalidArgumentException('invalid length for $lowest_priced_offers_inputs when calling CompetitiveSummaryRequest., number of items must be greater than or equal to 0.');
        }
        $this->container['lowest_priced_offers_inputs'] = $lowest_priced_offers_inputs;

        return $this;
    }

    /**
     * Gets method.
     */
    public function getMethod(): string
    {
        return $this->container['method'];
    }

    /**
     * Sets method.
     *
     * @param string $method method
     */
    public function setMethod(string $method): self
    {
        if (is_null($method)) {
            throw new \InvalidArgumentException('non-nullable method cannot be null');
        }
        $this->container['method'] = $method;

        return $this;
    }

    /**
     * Gets uri.
     */
    public function getUri(): string
    {
        return $this->container['uri'];
    }

    /**
     * Sets uri.
     *
     * @param string $uri the URI associated with the individual APIs that are called as part of the batch request
     */
    public function setUri(string $uri): self
    {
        if (is_null($uri)) {
            throw new \InvalidArgumentException('non-nullable uri cannot be null');
        }
        if (mb_strlen($uri) > 512) {
            throw new \InvalidArgumentException('invalid length for $uri when calling CompetitiveSummaryRequest., must be smaller than or equal to 512.');
        }
        if (mb_strlen($uri) < 6) {
            throw new \InvalidArgumentException('invalid length for $uri when calling CompetitiveSummaryRequest., must be bigger than or equal to 6.');
        }

        $this->container['uri'] = $uri;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
